package com.dz.risk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dz.risk.common.ResponseVO;
import com.dz.risk.common.SysConstant;
import com.dz.risk.common.exception.RRException;
import com.dz.risk.pojo.QueryParams;
import com.dz.risk.pojo.domain.DebtBasicInformationCalculationEntity;
import com.dz.risk.pojo.model.PageModel;
import com.dz.risk.service.BondRiskInformationSheetService;
import com.dz.risk.service.DebtBasicInformationCalculationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 债券基础信息扩展计算
 *
 * @author yinpl
 * @email 
 * @date 2021-07-14 13:55:53
 */
@RestController
@Api(tags = "债券基础信息扩展计算api", value = "债券基础信息扩展计算接口")
@RequestMapping("dz-ftsp/stest/debtbasicinformationcalculation")
public class DebtBasicInformationCalculationController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private DebtBasicInformationCalculationService debtBasicInformationCalculationService;
    @Autowired
    private BondRiskInformationSheetService bondRiskInformationSheetService;
    /**
     * 查询预警债券名单
     *
     */
    @ApiOperation("查询债券基础信息扩展计算")
    @GetMapping(value = "/query")
    public ResponseVO query(QueryParams queryParams) {
        IPage<DebtBasicInformationCalculationEntity> iPage =null;
        try {
            iPage = debtBasicInformationCalculationService.query(queryParams);

        } catch (RRException e) {
            e.printStackTrace();
            logger.error("查询预警债券名单失败！" + e);
            return new ResponseVO(e.getCode(), e.getMessage());
        }
        return ResponseVO.ok(iPage);

    }

    /**
     * 重算债券风险信息
     */
    @ApiOperation("计算债券风险信息")
    @GetMapping(value = "/roll")
    public ResponseVO roll( Long version, Integer bondType){
        try {
            if (version == null){
                return new ResponseVO(201,"缺少版本号，请输入版本号");
            }
            if (bondType != null) {
                debtBasicInformationCalculationService.roll(version,SysConstant.ONE);
                debtBasicInformationCalculationService.roll(version,SysConstant.TWO);
                debtBasicInformationCalculationService.roll(version,SysConstant.THREE);
            }else {
                bondRiskInformationSheetService.roll(version);
            }
        } catch (RRException e) {
            e.printStackTrace();
            return new ResponseVO(e.getCode(),e.getMessage());
        }


        return new ResponseVO(200,"计算成功");
    }
    /**
     * 重算债券风险信息
     *//*
    @ApiOperation("计算债券基础信息扩展计算")
    @PostMapping(value = "/roll")
    public ResponseVO roll(@RequestBody QueryParams queryParams){
        try {
            if (queryParams.getVersion() == null){
                return new ResponseVO(201,"缺少版本号，请输入版本号");
            }
            if (queryParams.getBondType() == null) {
                return new ResponseVO(201,"缺少页面类型，请输入页面类型");
            }
            debtBasicInformationCalculationService.roll(queryParams);
        } catch (RRException e) {
            e.printStackTrace();
            return new ResponseVO(e.getCode(),e.getMessage());
        }


        return new ResponseVO(200,"计算成功");
    }*/




}
